# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/17 19:44
# @Author   : Robot-Zsj
"""
description:

i:
1
0 1
3 2

o:
1
"""

import sys

malloc_size = int(input())

used = []

while True:
    try:
        start, count = map(int, input().split())
        end = start + count - 1
        used.append((start, end))
    except:
        break


def solution():
    if malloc_size <= 0 or malloc_size > 100:
        return -1

    memory = [0] * 100

    for s, e in used:
        if s < 0 or s >= 100:
            return -1

        if e < 0 or e >= 100:
            return -1

        for i in range(s, e + 1):
            if memory[i] != 0:
                return -1
            else:
                memory[i] = 1

    ans = -1

    min_size = sys.maxsize

    l = 0
    while l < 100:
        while l < 100 and memory[l] != 0:
            l += 1

        if l >= 100:
            break

        r = l + 1
        while r < 100 and memory[r] == 0:
            r += 1

        free_size = r - l

        if malloc_size <= free_size < min_size:
            min_size = free_size
            ans = l
        # 找下一个空闲内存
        l = r + 1
    return ans


print(solution())
